<template>
  <div @keyup.enter="getData()">
    <el-form class="query-form" :inline="true" :model="params">
      <el-form-item>
        <el-input v-model="params.census_number" placeholder="编号查询" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-button @click="getData()">
          <i class="fa fa-fw fa-search"></i>
          查询
        </el-button>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="dialogImportVisible = true">
          <i class="fa fa-fw fa-upload"></i>
          {{ importTitle }}
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData"></c-table>

    <div class="query-pagination">
      <el-pagination
        @current-change="getData"
        :current-page.sync="params.index"
        :page-size="params.size"
        layout="total, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>

    <import-excel
      :visible.sync="dialogImportVisible"
      :title="importTitle"
      :post-api="postUrl"
      :excel-template="excelTemplateUrl"
      @success="getData"
    ></import-excel>
  </div>
</template>
<script>
import ImportExcel from '@/components/ImportExcel'
import { mapGetters } from 'vuex'
import { queryTrouble } from '@vimi/utils-api'

export default {
  components: {
    ImportExcel,
  },
  props: {},
  data() {
    return {
      postUrl: '',
      importTitle: '导入调查报告',
      excelTemplateUrl: '/static/files/调查报告导入模板.xlsx',
      dialogImportVisible: false,

      loading: false,
      params: {
        index: 1,
        size: 10,
        census_number: '',
        'service_id.eq': '',
      },
      tableName: 'credit_census_report',
      tableData: [],
      totalCount: 0,
      tableColumns: [
        { attrs: { label: '借款主体', prop: 'customer_name' } },
        { attrs: { label: '尽调编号', prop: 'census_number' } },
        { attrs: { label: '报告内容', prop: 'report_content' } },
        { attrs: { label: '借款银行', prop: 'bank_name' } },
        { attrs: { label: '业务品种', prop: 'business_type' } },
        { attrs: { label: '风控人员', prop: 'risk_control_person' } },
        { attrs: { label: '担保期限', prop: 'warranty_period' } },
        { attrs: { label: '借款利率', prop: 'bank_rate' } },
        { attrs: { label: '担保费率', prop: 'warranty_rate' } },
        { attrs: { label: '担保方式', prop: 'warranty_method', minWidth: '200px' } },
        { attrs: { label: '受理日期', prop: 'accept_date' } },
        { attrs: { label: '调查日期', prop: 'survey_date' } },
        { attrs: { label: '经营历史及现状', prop: 'business_history', minWidth: '200px' } },
        { attrs: { label: '企业员工及管理模式描述', prop: 'management_model', minWidth: '200px' } },
        { attrs: { label: '经营模式', prop: 'business_model', minWidth: '200px' } },
        { attrs: { label: '未来发展计划', prop: 'future_plan', minWidth: '200px' } },
        { attrs: { label: '投入备注', prop: 'input_remark', minWidth: '200px' } },
        { attrs: { label: '个人银行流水说明', prop: 'bank_flow_person_des', minWidth: '200px' } },
        { attrs: { label: '企业银行流水说明', prop: 'bank_flow_ent_des', minWidth: '200px' } },
        { attrs: { label: '财务数据核实', prop: 'finance_data_verify', minWidth: '200px' } },
        { attrs: { label: '财务指标备注', prop: 'finance_norm_remark', minWidth: '200px' } },
        { attrs: { label: '财务报表备注', prop: 'finance_remark', minWidth: '200px' } },
        { attrs: { label: '借款原因及用途', prop: 'borrowing_reason', minWidth: '200px' } },
        { attrs: { label: '还款计划及还款能力', prop: 'repayment_plan', minWidth: '200px' } },
        { attrs: { label: '反担保措施', prop: 'counter_guarantee', minWidth: '200px' } },
        {
          attrs: {
            label: '反担保措施评价',
            prop: 'counter_guarantee_evaluation',
            minWidth: '200px',
          },
        },
        { attrs: { label: '优势分析', prop: 'advantage_analysis', minWidth: '200px' } },
        { attrs: { label: '劣势分析', prop: 'disadvantage_analysis', minWidth: '200px' } },
        { attrs: { label: '项目风险分析', prop: 'project_risk_analysis', minWidth: '200px' } },
        { attrs: { label: '贷款资金支付情况', prop: 'loan_payment' } },
        { attrs: { label: '调查报告意见', prop: 'census_opinion', minWidth: '200px' } },
        { attrs: { label: '调查员A角', prop: 'res_a_name' } },
        { attrs: { label: '调查员A角意见', prop: 'a_opinion', minWidth: '200px' } },
        { attrs: { label: '调查员B角', prop: 'res_b_name' } },
        { attrs: { label: '调查员B角意见', prop: 'b_opinion', minWidth: '200px' } },
        { attrs: { label: '用电分析', prop: 'ele_analysis_des', minWidth: '200px' } },
        { attrs: { label: '偿债能力分析', prop: 'debt_analysis_des', minWidth: '200px' } },
        { attrs: { label: '行政信息描述', prop: 'adm_des' } },
        { attrs: { label: '司法信息描述', prop: 'jud_des' } },
        { attrs: { label: '评估金额', prop: 'eva_funds' } },
        { attrs: { label: '评估金额理由', prop: 'eva_reason' } },
        { attrs: { label: '直接评估人签字', prop: 'eva_person' } },
        { attrs: { label: '信用风险', prop: 'credit_risk_analysis' } },
        { attrs: { label: '偿债风险', prop: 'debt_risk_analysis' } },
        { attrs: { label: '经营业务说明(主营和副营)', prop: 'business_des' } },
        { attrs: { label: '采购模式分析', prop: 'purchase_model_des' } },
        { attrs: { label: '生产模式分析', prop: 'produce_des' } },
        { attrs: { label: '销售模式分析', prop: 'sell_model_des' } },
        { attrs: { label: '技术保障', prop: 'tech_support_des' } },
        { attrs: { label: '经营流水说明', prop: 'bank_flow_des' } },
        { attrs: { label: '农业保险说明', prop: 'arg_insurance_des' } },
        { attrs: { label: '涉诉描述', prop: 'involved_des' } },
        { attrs: { label: '企业非财务情况分析结论', prop: 'non_finance_result' } },
        { attrs: { label: '有权审批人意见(信贷负责人意见)', prop: 'approval_option' } },
        { attrs: { label: '资产负债表核实', prop: 'finance_assets_verify' } },
        { attrs: { label: '企业收入核实', prop: 'finance_income_verify' } },
        { attrs: { label: '成本核实', prop: 'finance_cost_verify' } },
        { attrs: { label: '其它科目核实', prop: 'finance_other_verify' } },
        { attrs: { label: '检验核实结果', prop: 'finance_verify_result' } },
        { attrs: { label: '风控人意见', prop: 'risk_option' } },
        { attrs: { label: '贷款人身份证号', prop: 'lender_idcard' } },
        { attrs: { label: '第三方评价-村委会', prop: 'third_evalue_burg' } },
        { attrs: { label: '第三方评价-乡镇', prop: 'third_evalue_village' } },
        { attrs: { label: '第三方评价-左邻右舍', prop: 'third_evalue_lr' } },
        { attrs: { label: '第三方评价-同行', prop: 'third_evalue_sm' } },
        { attrs: { label: '第三方评价-上游', prop: 'third_evalue_upper' } },
        { attrs: { label: '第三方评价-下游', prop: 'third_evalue_lower' } },
        { attrs: { label: '第三方评价-其它', prop: 'third_evalue_other' } },
      ],
    }
  },
  computed: {
    ...mapGetters(['clientId', 'job']),
    superJob() {
      return [
        'org_credit_super',
        'org_c_manage',
        'org_r_manage',
        'org_p_manage',
        'org_c_general',
      ].includes(this.job)
    },
  },
  watch: {},
  created() {
    this.params['service_id.eq'] = this.clientId
    this.postUrl =
      '/api/credit/import/' +
      queryTrouble(this.tableName, {
        importKey: `${this.tableName}_template`,
        'service_id.eq': this.clientId,
        'customer_related_id.eq': 'relatedId',
      })

    this.getData()
  },
  mounted() {},
  methods: {
    async getData() {
      this.loading = true
      let [res, err] = await this.$utils.promise(
        this.$api.getData('credit', this.tableName, this.params, { create_time: 'desc' })
      )
      this.loading = false

      if (err) {
        return this.$message.error('获取数据失败，请稍后重试！')
      }

      const data = (res && res.data) || {}
      this.tableData = data.data || []
      this.totalCount = data.totalCount || 0
    },
  },
}
</script>
<style scoped></style>
